package cn.wp.ewallet.wallet.dao.impl;

import cn.wp.common.core.dao.JdbcSupportTemplate;
import cn.wp.common.core.dao.SqlString;
import cn.wp.common.core.model.WpPage;
import cn.wp.ewallet.wallet.dao.RechargeShqcLogDao;
import cn.wp.ewallet.wallet.model.dto.RechargeLogDto;
import cn.wp.ewallet.wallet.model.entity.RechargeLogDoo;
import cn.wp.ewallet.wallet.model.entity.RechargeShqcLogDo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName RechargeShqcLogDaoImpl
 * @Author ruixule
 * @Date 2020/1/10 17:45
 */
@Repository
public class RechargeShqcLogDaoImpl implements RechargeShqcLogDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;
    @Override
    public void saveRechargeShqcLog(RechargeShqcLogDo rechargeShqcLogDo) {
        jdbcSupportTemplate.insert(rechargeShqcLogDo);
    }

    @Override
    public WpPage<RechargeShqcLogDo> selectAllRechargeLog(RechargeLogDoo rechargeLogDoo, WpPage wpPage) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select r.recharge_id, r.address_to, r.currency_type, r.shqc_amount, s.sys_user_code as oper_user, r.oper_time");
        sqlString.add("from recharge_shqc_log r, system_user_info s");
        sqlString.add("    where r.oper_user = s.sys_user_id");
        List<String> params = new ArrayList<>();
        if (StringUtils.isNotEmpty(rechargeLogDoo.getBeginDate())) {
            sqlString.add("    and r.oper_time > ?");
            params.add(rechargeLogDoo.getBeginDate());
        }

        if (StringUtils.isNotEmpty(rechargeLogDoo.getEndDate())) {
            sqlString.add("    and r.oper_time < ?");
            params.add(rechargeLogDoo.getEndDate());
        }
        if (StringUtils.isNotEmpty(rechargeLogDoo.getRechargeId())) {
            sqlString.add("    and r.recharge_id = ?");
            params.add(rechargeLogDoo.getRechargeId());
        }
        sqlString.add(" order by r.oper_time desc");
        return jdbcSupportTemplate.selectList(sqlString.build(), params.toArray(), wpPage,RechargeShqcLogDo.class);
    }
}
